You are looking at historical revision 35318 of this page. It may differ significantly from its current revision.

Statically linked applications

-----

The most portable way of creating separately linkable entities is supported by so-called units. A unit is a single compiled object module that contains a number of toplevel expressions that are executed either when the unit is the main unit or if the unit is used. To use a unit, the unit has to be declared as used, like this:

(declare (uses UNITNAME))

The toplevel expressions of used units are executed in the order in which the units appear in the uses declaration. Units may be used multiple times and uses declarations may be circular (the unit is initialized at most once). To compile a file as a unit, add a unit declaration:

(declare (unit UNITNAME))

When compiling different object modules, make sure to have one main unit. This unit is called initially and initializes all used units before executing its toplevel expressions. The main-unit has no unit declaration.

Another method of using definitions in separate source files is to include them. This simply inserts the code in a given file into the current file:

(include "FILENAME")

Macro definitions are only available when processed by include or import. Macro definitions in separate units are not available, since they are defined at compile time, i.e the time when that other unit was compiled (macros can optionally be available at runtime, see define-syntax in Substitution forms and macros).